package trinnes.oliver.unimaas.smartpentalath.intelligence;

/**
 * Simple bubble sort because it is called very rarely.
 * @author Oliver Trinnes
 */
public class Sort
{
  public static void bubbleSort(int[][] movesAndValues)
  {
    int n = movesAndValues.length;
    while(true)
    {
      boolean swapped = false;
      for(int i = 1; i<n; i++)
      {
        if(movesAndValues[i-1][1] < movesAndValues[i][1])
        {
          swap(movesAndValues, i-1, i);
          swapped = true;
        }
      }
      n = n-1;
      if(!swapped)
        break;
    }
  }
  private static void swap(int[][] array, int i, int j)
  {
    int tempMove = array[i][0];
    int tempValue = array[i][1];
    
    array[i][0] = array[j][0];
    array[i][1] = array[j][1];
    array[j][0] = tempMove;
    array[j][1] = tempValue;
  }
}
